<template>
	<view style="width: 100%;" >
		<view class="item" @click="show=!show" >
			<u--input inputAlign="right" v-model="text" disabled disabledColor="transparent" :placeholder="placeholder" border="none"></u--input>
			<u-icon name="arrow-right"></u-icon>
		</view>
		
		<u-picker :keyName='selectLabel' :columns="[radiolist]" :show="show" @confirm="confirm" @cancel='show=false' @close="show=false"></u-picker>
	</view>
</template>

<script>
	export default {
		name: 'smma-picker',
		props: {
			placeholder:{
				type: String,
				default: '请选择'
			},
			selectLabel: {
				type: String,
				default: 'text'
			},
			selectValue: {
				type: String,
				default: 'value'
			},
			option: {
				type: Array,
				default: () => []
			},
			dictCode: {
				type: String,
				default: ''
			},
	
			url: {
				type: String,
				default: ''
			},
			value: {
				type: String,
				default: ''
			},
		
		},
		data() {
			return {
				text:'',
				show:false,
				radiolist: [],
			}
		},
		watch:{
			value:{
				handler(o,v) {
					console.log(o,v,1223123)
				}
			}
		},
		async created() {
			if (this.option && this.option.length) {
				this.radiolist = this.option
			} else if (this.dictCode) {
				if (!uni.getStorageSync('sysAllDictItems')[this.dictCode]) {
					this.radiolist = uni.getStorageSync('sysAllDictItems')[this.dictCode];
				} else {
					let res = await this.$getRequest('/sys/dict/getDictItems/' + this.dictCode);
					this.radiolist = res.result || []
				}
			} else if (this.url) {
				let res = await this.$getRequest(this.url);
				this.radiolist = res.result.records ||res.result|| []
			} else {
				this.$util.msg('请设置数据来源')
			}
			//初始化有问题
		},

		methods: {
			confirm(e) {
				this.text = e.value[0][this.selectLabel];
				this.value = e.value[0][this.selectValue];
				this.show = false;
				this.$emit("input", this.value)
			},

		}
	}
</script>

<style scoped lang="scss">
	.item {
		display: flex;
		.u-input {
			pointer-events:none;
		}
	}
</style>